<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
    <ButlerServiceOrderDetailModal @register="registerButlerServiceOrderDetailModal"></ButlerServiceOrderDetailModal>
    <OrderCommentDrawer @register="registerOrderCommentDrawer" />
    <OrderRewardDrawer @register="registerOrderRewardDrawer" />
  </div>
</template>
<script lang="ts" setup name="butlerServiceOrder">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/table';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { columns, searchFormSchema } from './data/data';
import { useModal } from '@apps/antd-admin/src/components/modal';
import ButlerServiceOrderDetailModal from './components/ButlerServiceOrderDetailModal.vue';
import OrderCommentDrawer from './components/OrderCommentDrawer.vue';
import OrderRewardDrawer from './components/OrderRewardDrawer.vue';
import { Api } from './data/api';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';

const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'butlerServiceOrder-template',
  tableProps: {
    //表格标题
    title: '管家服务订单列表',
    //主键字段
    rowKey: 'butlerServiceOrderId',
    //列表查询handler
    handlerName: 'busOrderRewardListHandler',
    //列表接口
    listUrl: Api.page,
    //列定义
    columns: columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      showExportButton: true,
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 180,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    clickToRowSelect: true,
    rowSelection: {
      type: 'radio',
    },
    //查询前处理
    beforeFetch: params => {
      params.airportIds = '';
      let airportIdArray: any = params.airportIdArray;
      console.info('--------------beforeFetch-------airportIdArray--------------------------', airportIdArray);
      if (airportIdArray) {
        params.airportIds = airportIdArray.join(',');
      }
      delete params.airportIdArray;
      return params;
    },
  },
});

const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;
const [registerButlerServiceOrderDetailModal, { openModal: openButlerServiceOrderDetailModal }] = useModal();
const [registerOrderCommentDrawer, { openDrawer: openOrderCommentDrawer }] = useDrawer();
const [registerOrderRewardDrawer, { openDrawer: openOrderRewardDrawer }] = useDrawer();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '查看详情',
      onClick: handleLookDetailData.bind(null, record),
    },
  ];
}

/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [
    {
      label: '查看订单评价',
      onClick: handleLookOrderComment.bind(null, record),
    },
    {
      label: '查看打赏记录',
      onClick: handleLookOrderReward.bind(null, record),
    },
  ];
}

function handleLookDetailData(record) {
  openButlerServiceOrderDetailModal(true, {
    record,
    isUpdate: false,
  });
}

function handleLookOrderComment(record) {
  openOrderCommentDrawer(true, {
    record,
    isUpdate: true,
  });
}

function handleLookOrderReward(record) {
  openOrderRewardDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
